package com.camus.utils;

public class NumberUtils {

	/**
	 * 计算x的n次幂 
	 * eg. NumberUtils.pow(3,2)=9
	 * 
	 * @param x
	 * @param n
	 * @return
	 */
	public static int pow(int x, int n) {
		assert n >= 0;
		int mul = 1;
		int i = 0;
		while (i++ < n) {
			mul *= x;
		}
		return mul;
	}

	public static boolean[] toBoolArr(long num, int len) {
		assert num >= 0;
		assert len > 0;

		boolean[] flagArr = new boolean[len];

		int i = len - 1;
		while (num > 0 && i >= 0) {
			flagArr[i--] = (num & 1) == 1;
			num = num >> 1;
		}

		return flagArr;
	}

}
